home *** CD-ROM | disk | FTP | other *** search
- #define DISABLE_LOCAL_CALLTRACE 1 // Set to 1 to disable Call Traces for this file.
- #define DISABLE_LOCAL_DEBUG 0 // Set to 1 to disable all debugging for this file.
- #include "DebugUtils.h"
-
- #include <Errors.h>
- #include <Gestalt.h>
- #include <Memory.h>
- #include <Resources.h>
- #include "PatchHarness.h"
-
-
-
-
-
- #ifdef __cplusplus
- extern "C" {
- #endif
-
- static Boolean OnPowerPC(void);
-
- #ifdef __cplusplus
- }
- #endif
-
-
-
-
-
- // Load patch harnesses for all the system functions that
- // we need to hook. These harnesses will allow us to unload
- // and reload ourselves without rebooting by giving us the
- // ability to change the patch chain whenever we want.
- OSStatus InstallPatchHarness(PatchDesc **patchList)
- {
- Handle code;
- short index;
- OSStatus err;
-
-
- // Keep things somewhat generic, just index thru and load all
- // the 'PTCH' code resources, they contain all the 68K harnesses.
- index = 1;
- while((code = Get1IndResource('PTCH',index++)) != NULL)
- {
- // Make sure the code resource will
- // stick around after we are gone.
- DetachResource(code);
- HLock(code);
-
- // Install the patch harness.
- err = CallPatchInitProc(*code,patchList);
- if (err != noErr)
- {
- DisposeHandle(code);
- return err;
- }
- }
-
- if (OnPowerPC())
- {
- // Keep things somewhat generic, just index thru and load all
- // the 'ptch' code resources, they contain all the PPC harnesses.
- index = 1;
- while((code = Get1IndResource('ptch',index++)) != NULL)
- {
- // Make sure the code resource will
- // stick around after we are gone.
- DetachResource(code);
- HLock(code);
-
- // Install the patch harness.
- err = CallPatchInitProc(*code,patchList);
- if (err != noErr)
- {
- DisposeHandle(code);
- return err;
- }
- }
- }
-
- return noErr;
- }
-
-
-
-
-
- OSStatus InstallPatch(PatchDesc *patchList,OSType type,UniversalProcPtr patch)
- {
- PatchDesc *desc;
-
-
- // Find patch descriptor that matches type.
- for (desc = patchList;desc != NULL;desc = desc->next)
- if (desc->type == type)
- {
- // Check that its OK to install.
- if (desc->install == NULL)
- return -1;
-
- // Install the patch.
- CallPatchInstallProc(desc->install,desc,patch);
- return noErr;
- }
-
- // Unknown type.
- return -1;
- }
-
-
-
-
-
- OSStatus RemovePatch(PatchDesc *patchList,OSType type)
- {
- PatchDesc *desc;
-
-
- // Find patch descriptor that matches type.
- for (desc = patchList;desc != NULL;desc = desc->next)
- if (desc->type == type)
- {
- // Check that its OK to remove.
- if (desc->remove == NULL)
- return -1;
-
- // Remove the current patch.
- CallPatchRemoveProc(desc->remove,desc);
- return noErr;
- }
-
- // Unknown type.
- return -1;
- }
-
-
-
-
-
- Boolean OnPowerPC(void)
- {
- long result;
- OSStatus err;
-
-
- result = gestalt68k;
- err = Gestalt(gestaltSysArchitecture,&result);
- if ((err == noErr) && (result == gestaltPowerPC))
- return true;
-
- return false;
- }
-